/**
 * 
 */
package trungsi.gea.photos.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author trungsi
 *
 */
public class StreamUtils {

	public static byte[] toByteArray(InputStream inputStream) throws IOException {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
		byte[] buffer = new byte[1024];
		int read;
		while ((read = inputStream.read(buffer)) != -1) {
			outputStream.write(buffer, 0, read);
		}
		inputStream.close();
		return outputStream.toByteArray();
	}

	public static InputStream toInputStream(byte[] byteArray) {
		return new ByteArrayInputStream(byteArray);
	}
}
